home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Conic Sections 0.9.2 / Sources / DocContent.cpp < prev    next >
Encoding:
Text File  |  1997-06-08  |  3.0 KB  |  143 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "DocContent.h"
  5. #include "MenuHandler.h"
  6. #include <Scrap.h>
  7. #include <Drag.h>
  8. #include "CLApplication.h"
  9. #include "Messages.h"
  10.  
  11. TDocContent::TDocContent( TLayoutBranch *super, Boolean hasDD, MActionHandler *superHandler, TPlane *plane ):
  12.     TLayoutLeaf( super ),
  13.     MActionHandler( superHandler ),
  14.     mPlane( plane ),
  15.     mHasDragDrop( hasDD )
  16. {
  17.     mPlane->AddReceiver( this );
  18. }
  19.  
  20. Boolean TDocContent::Init()
  21. {
  22.     TLayoutLeaf::Init();
  23. }
  24.  
  25. Boolean TDocContent::MakeActive( Boolean active )
  26. {
  27.     Boolean retVal= TLayoutLeaf::MakeActive( active );
  28.     if( retVal && active )
  29.         MakeActive();
  30.     return( retVal );
  31. }
  32.  
  33. SInt8 TDocContent::MakeActive()
  34. {
  35.     return( MActionHandler::MakeActive() );
  36. }
  37.  
  38. SInt8 TDocContent::HandleAction( UInt32 message )
  39. {
  40.     UInt16 menu, item;
  41.  
  42.     menu= message>>16;
  43.     item= message&0x00ff;
  44.     switch( menu ) {
  45.     case m_EDIT:
  46.         switch( item ) {
  47.         case me_COPY:
  48.             CopySelf();
  49.             break;
  50.         }
  51.         break;
  52.     }
  53.     if( mSuperHandler )
  54.         return( mSuperHandler->HandleAction( message ) );
  55.     return( 1 );
  56. }
  57.  
  58. TPicture *TDocContent::GetPicture()
  59. {
  60.     TPicture *picture;
  61.     picture= new TPicture( GetLocalRect() );
  62.     Draw( picture );
  63.     return( picture );
  64. }
  65.  
  66. void TDocContent::CopySelf()
  67. {
  68.     TPicture *picture;
  69.     PicHandle image;
  70.  
  71.     ::ZeroScrap();
  72.     picture= GetPicture();
  73.     image= picture->GetPic();
  74.     MoveHHi( (Handle)image );
  75.     HLock( (Handle)image );
  76.     PutScrap( GetHandleSize( (Handle)image ), 'PICT', *image );
  77.     HUnlock( (Handle)image );
  78.     delete picture;
  79. }
  80.  
  81. Rect TDocContent::GetLargestSize()
  82. {
  83.     Rect largRect;
  84.     ::SetRect( &largRect, 0, 0, 32700, 32700 );
  85.     return( largRect );
  86. }
  87.  
  88. int TDocContent::ReceiveMessage( TMessage *msg )
  89. {
  90.     switch( msg->mWhat ) {
  91.     case kUpdateWindow:
  92.         Draw( mWindow );
  93.         return( 1 );
  94.     default:
  95.         return( 0 );
  96.     }
  97.     return( 1 );
  98. }
  99.  
  100. Boolean TDocContent::HandleMouseSelf( TMouseButtonEvent *ev )
  101. {
  102.     if( !mHasDragDrop )
  103.         return( true );
  104.     if( ::WaitMouseMoved( ev->where ) ) {
  105.         GWorldPtr oldWorld;
  106.         GDHandle oldDevice;
  107.         ::GetGWorld( &oldWorld, &oldDevice );
  108.         GWorldPtr newWorld;
  109.         GDHandle newDevice;
  110.         TApplication::SCurApp()->GetGlobalWorld( newWorld, newDevice );
  111.         ::SetGWorld( newWorld, newDevice );
  112.         DragReference drag;
  113.         ::NewDrag( &drag );
  114.         RgnHandle dragRgn= ::NewRgn(), inRgn= ::NewRgn();
  115.         ::RectRgn( dragRgn, &mContentRect );
  116.         ::CopyRgn( dragRgn, inRgn );
  117.         ::InsetRgn( inRgn, 1, 1 );
  118.         ::DiffRgn( dragRgn, inRgn, dragRgn );
  119.         ::DisposeRgn( inRgn );
  120.         Point pt;
  121.         pt.h= 0; pt.v= 0;
  122.         mWindow->LocalToGlobal( &pt );
  123.         ::OffsetRgn( dragRgn, pt.h, pt.v );
  124.         TPicture *picture= GetPicture();
  125.         PicHandle image= picture->GetPic();
  126.         ::HLock( (Handle)image );
  127.         ::AddDragItemFlavor( drag, 1, 'PICT', *image, ::GetHandleSize( (Handle)image ), 0 );
  128.         ::HUnlock( (Handle)image );
  129.         EventRecord myEv;
  130.         myEv.where= ev->where;
  131.         mWindow->LocalToGlobal( &myEv.where );
  132.         ::TrackDrag( drag, &myEv, dragRgn );
  133.         ::DisposeDrag( drag );
  134.         ::DisposeRgn( dragRgn );
  135.         ::PenPat( &qd.black );
  136.         RGBColor black;
  137.         black.red= 0; black.green= 0; black.blue= 0;
  138.         ::RGBForeColor( &black );
  139.         ::SetGWorld( oldWorld, oldDevice );
  140.         delete picture;
  141.     }
  142.     return( true );
  143. }